﻿using System;
using System.Text;
using System.Configuration;


namespace ClassFactory
{
    /// <summary>
    /// Class Factory to create concrete factories either on remote machine or local machine    
    /// </summary>
    public class CClassFactory
    {
        /// <summary>
        /// Constructor
        /// </summary>
        private CClassFactory()
        {
        }

        /// <summary>
        /// Get the concrete factory
        /// </summary>
        public static object GetFactory(IFactoryObject iFactoryObject_p)
        {
            object objFactory = null;

            string strType = iFactoryObject_p.Type;
            Type type = System.Type.GetType(strType);

            //creat an instance of concrete class factory
            if (iFactoryObject_p.Location.Equals("Local") == false)
            {
                string strLocation = iFactoryObject_p.Location;
                //create concrete object using .NET remoting
                objFactory = Activator.GetObject(type, strLocation);
            }
            else
            {
                //create object on the same machine
                objFactory = Activator.CreateInstance(type, null);
            }
            return objFactory;
        }
    
    }

}
